export default {
	name: "batch-entities",
	data() {
		return {
			mainColumns: [
				{"label": "编号", "prop": "id", "kind": "input", "width": 160, "disabled": true},
				{"label": "项目名", "prop": "project", "kind": "input", "width": 240, "disabled": false},
				{"label": "包名", "prop": "package", "kind": "input", "disabled": false},
				{"label": "父目录", "prop": "parent", "kind": "input", "width": 240, "disabled": false},
				{"label": "类名", "prop": "className", "kind": "input", "width": 240, "disabled": false},
				{
					"label": "是否更新", "prop": "isUpdate", "kind": "select", "width": 160, "disabled": false,
					selectOptions: this.constants.select.booleanOptions
				}
			],
			childColumns: [
				{"label": "字段名", "prop": "fieldName", "kind": "input", "width": 180, "disabled": false},
				{"label": "字段类型", "prop": "fieldType", "kind": "input", "width": 280, "disabled": false},
				{"label": "字段注释", "prop": "fieldComment", "kind": "input", "disabled": false}
			],
			rowId: 0,
			dialogVisible: false,
			mainData: [],
			childData: []
		};
	},
	created() {
		this.initData();
	},
	methods: {
		initData() {
			this.mainData.push({
				id: 1,
				project: "boot-jdbc",
				package: "com.broad.commerce.jdbc.models",
				parent: "",
				className: "",
				isUpdate: false,
				data: []
			});
		},
		rowClick(row, column, event) {
			this.childData = [];
			this.rowId = row.id;
			this.dialogVisible = true;
			this.childData.push({
				fieldName: "",
				fieldType: "",
				fieldComment: ""
			});
		},
		saveData() {
			console.log(this.mainData);
		},
		submitData() {
			console.log(this.childData);
			if (this.rowId > 0) {
				let entity = this.mainData.filter(entity => entity.id === this.rowId)[0];
				entity.data = this.childData;
			}
			this.dialogVisible = false;
		},
		appendMainRow(rowIndex) {
			this.dialogVisible = false;
			this.mainData.push({
				id: this.mainData.length + 1,
				project: "boot-jdbc",
				package: "com.broad.commerce.jdbc.models",
				parent: "",
				className: "",
				isUpdate: false,
				data: []
			});
		},
		removeMainRow(rowIndex) {
			this.dialogVisible = false;
			if (rowIndex === 0) {
				return;
			}
			this.mainData.splice(rowIndex, 1);
		},
		appendChildRow(rowIndex) {
			this.childData.push({
				fieldName: "",
				fieldType: "",
				fieldComment: ""
			});
		},
		removeChildRow(rowIndex) {
			if (rowIndex === 0) {
				return;
			}
			this.childData.splice(rowIndex, 1);
		}
	}
};
